<?php
	session_start();

	if(isset($_SESSION['username']))
	{
		$username = $_SESSION['username'];
	}
	else
	{
		$key = $_GET['key'];
		if(isset($key))
		{
			include 'config.php';
			$stmt = $con->prepare('SELECT Login FROM User WHERE ResetKey = ?');
			$stmt->bind_param('s', $key);
			$stmt->execute();
			
			$result = $stmt->get_result();
			
		
			
			$count=mysqli_num_rows($result);
			if($count == 1)
			{
				$row = $result->fetch_assoc();
				
				$username = $row['Login'];
			}
			else
			{
				$_SESSION['message'] = "Not a valid reset key.";
				header ("Location: index.php");
			}
			mysqli_close($con);
		}
		else
		{
			$_SESSION['message'] = "Not a valid reset key.";
			header ("Location: index.php");
		}
		
		
	}
	include("LangHeader.php");
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<?php echo $LangScript; ?>
<title>Sales Makeover</title>
</head>

<body style='background-image: url("content/login_background_2.jpg"); background-position:50% 0%;'>
	<div class="container_head">
		<div class="login_container_head_content">
			<div style='height:100px;'>
				<div style='float:right;margin-top:25px;'>
				<a href="http://leadsmachine.se/index.php" class="headline_link">
					<img src="content/salesmakeover_logo.png" height="60%" width="60%"  >
					<div style="font-family: Arial; font-size:12px; color:#666666;margin-top:5px;">salesmakeover.se</div></a>
				</div>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="form_container">
			<?php 
				if(isset($_GET['key']))
				{
					$key = $_GET['key'];
					echo "<form id=\"form_add\" class=\"form_add\" method=\"post\" action=\"reseting.php?key=" . $key . "\" accept-charset=\"UTF-8\">";
				}
				else
				{
					echo "<form id=\"form_add\" class=\"form_reset\" method=\"post\" action=\"reseting.php\" accept-charset=\"UTF-8\">";
				}
				echo "<div class=\"LoginLabel tr\" key=\"username\"></div>";
				if(isset($username))
				{
					echo "<input type=\"email\" name=\"login\" disabled value=\"" . $username . "\">";
				}
				else
				{
					echo "<input type=\"email\" name=\"login\">";
				
				}
				
				if(isset($key))
				{
					echo "<div class=\"LoginLabel tr\" key=\"newpassword\"></div>";
					echo "<input type=\"password\" name=\"password\" >";
				}
					
				echo "<input style=\"margin-left: 285px; margin-right:auto;margin-top:40px;\" type=\"submit\" class=\"button tr\" key=\"Send\">";
				echo "</form>";
					
			?>
				
		</div>
	</div>
</body>

</html>